#!/bin/bash

# **********************************************************************************
# Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
# [openeuler-jenkins] is licensed under the Mulan PSL v1.
# You can use this software according to the terms and conditions of the Mulan PSL v1.
# You may obtain a copy of Mulan PSL v1 at:
#     http://license.coscl.org.cn/MulanPSL
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v1 for more details.
# Author: wangge
# Create: 2021-10-29
# **********************************************************************************
usage="Usage: query_history_build_time_of_package(PROJECT, REPOSITORY, PACKAGE, BOUNDARY)\n
Get a package build time, in recent [RANGE] TIME\n
PROJECT\t: project name\n
REPOSITORY:\t: reposiroty name\n
PACKAGE\t: package name\n
BOUNDARY\t: recent times to be statistic\n"

if [[ "${*}" =~ "--help" ]];then
echo -e $usage
exit 0
fi

#check validity of parameter num
if [ $# -ne 4 ];then
echo "Invalid parameter"
echo -e $usage
exit 0
fi

#recognition validity of range
if [ $4 -gt 30 ] || [ $4 -lt 1 ];then
echo "boundary range should between 1 to 30"
echo -e $usage
exit 0
fi

#recognition validity of project
osc list $1 > /dev/null 2>&1
if [ $? -eq 1 ];then
echo "Invalid project name"
echo -e $usage
exit 0
fi

#recognition validity of architecture
result=`osc api -X GET /published/$1/$2?view=status | grep -c unknown`
if [ $result -eq 1 ];then
echo "Invalid repository name"
echo -e $usage
exit 0
fi

#recognition validity of package
osc list $1 | grep -x $3
if [ $? -eq 1 ];then
echo "Invalid package name"
echo -e $usage
exit 0
fi


#generate result file for project
exit 0
#clean temp file

